﻿using Neatly.UI;
using UnityEditor;
using UnityEngine;

namespace NeatlyEditor.UI
{
    [CustomEditor(typeof(NInternational), true)]
    [CanEditMultipleObjects]
    public class NInternationalEditor : Editor
    {
        SerializedProperty m_SpriteName1;
        SerializedProperty m_SpriteName2;
        SerializedProperty m_Clip1;
        SerializedProperty m_Clip2;
        GUIContent m_SpriteName1Content;
        GUIContent m_SpriteName2Content;
        GUIContent m_Clip1Content;
        GUIContent m_Clip2Content;

        protected void OnEnable()
        {
            m_SpriteName1 = serializedObject.FindProperty("m_SpriteName1");
            m_SpriteName2 = serializedObject.FindProperty("m_SpriteName2");
            m_Clip1 = serializedObject.FindProperty("m_Clip1");
            m_Clip2 = serializedObject.FindProperty("m_Clip2");
            
            m_SpriteName1Content = new GUIContent("默认 SpriteName");
            m_SpriteName2Content = new GUIContent("阿语 SpriteName");
            m_Clip1Content = new GUIContent("默认 动画Clip");
            m_Clip2Content = new GUIContent("阿语 动画Clip");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            DrawGUI();
            serializedObject.ApplyModifiedProperties();
        }

        private void DrawGUI()
        {
            NInternational component = target as NInternational;
            InspectorHelper.BeginGroup();
            component.IsImage = InspectorHelper.Toggle("Image", component.IsImage, true);
            if (component.IsImage)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_SpriteName1, m_SpriteName1Content);
                EditorGUILayout.PropertyField(m_SpriteName2, m_SpriteName2Content);
                EditorGUI.indentLevel--;
            }
            InspectorHelper.EndGroup();
            InspectorHelper.BeginGroup();
            component.IsAnimation = InspectorHelper.Toggle("Animation", component.IsAnimation, true);
            if (component.IsAnimation)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_Clip1, m_Clip1Content);
                EditorGUILayout.PropertyField(m_Clip2, m_Clip2Content);
                EditorGUI.indentLevel--;
            }
            InspectorHelper.EndGroup();
        }
    }
}